package com.zxy.express.controller;

import com.autopai.base.common.web.constant.Constant;
import com.autopai.base.common.web.model.RestResult;
import com.autopai.base.common.web.page.PageData;
import com.autopai.base.common.web.validator.ValidatorUtils;
import com.autopai.base.common.web.validator.group.AddGroup;
import com.autopai.base.common.web.validator.group.DefaultGroup;
import com.autopai.base.common.web.validator.group.UpdateGroup;
import com.zxy.express.dto.ReciteMaterialDTO;
import com.zxy.express.service.ReciteMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;


/**
 * 背诵素材表
 *
 * @author zhangxiying ${email}
 * @since ${version} 2025-07-01
 */
@RestController
@RequestMapping("recitematerial")
@Api(tags="背诵素材表")
public class ReciteMaterialController {
    @Autowired
    private ReciteMaterialService reciteMaterialService;

    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
        @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String")
    })
    public RestResult<PageData<ReciteMaterialDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<ReciteMaterialDTO> page = reciteMaterialService.page(params);

        return new RestResult<PageData<ReciteMaterialDTO>>().ok(page);
    }

    @GetMapping("getById")
    @ApiOperation("信息")
    public RestResult<ReciteMaterialDTO> get(@RequestParam String id){
        ReciteMaterialDTO data = reciteMaterialService.get(id);

        return new RestResult<ReciteMaterialDTO>().ok(data);
    }

    @PostMapping
    @ApiOperation("保存")
    public RestResult save(@RequestBody ReciteMaterialDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);

        reciteMaterialService.save(dto);

        return new RestResult();
    }

    @PutMapping
    @ApiOperation("修改")
    public RestResult update(@RequestBody ReciteMaterialDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);

        reciteMaterialService.update(dto);

        return new RestResult();
    }

    @PostMapping("updateByTitle")
    @ApiOperation("修改")
    public RestResult updateByTitle(@RequestBody ReciteMaterialDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);

        reciteMaterialService.updateByTitle(dto);

        return new RestResult();
    }

    @DeleteMapping
    @ApiOperation("删除")
    public RestResult delete(@RequestBody String[] ids){
        //效验数据
       // AssertUtils.isArrayEmpty(ids, "id");

        reciteMaterialService.delete(ids);

        return new RestResult();
    }

}